import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.PooledConnection;

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;


public class DB {
	private static MysqlConnectionPoolDataSource mstDataSource;
	
	public static synchronized Connection getConnectionRead() throws
	SQLException, IOException {
	    if (mstDataSource  == null) {
	    	Properties prop = new Properties();
	    	prop.load(new FileInputStream("db.properties"));
	    	mstDataSource = new MysqlConnectionPoolDataSource();
	    	mstDataSource.setDatabaseName(prop.getProperty("db"));
	    	mstDataSource.setServerName(prop.getProperty("host"));
	    	mstDataSource.setUser(prop.getProperty("username"));
	    	mstDataSource.setPassword(prop.getProperty("pass"));
	        
	    }
	    PooledConnection pc = mstDataSource.getPooledConnection();
	    return pc.getConnection();
	}
	
}
